//  https://www.luogu.com.cn/problem/P1115

#include<iostream>
using namespace std;

typedef long long LL;
const int N = 2e5 + 10;
LL a[N];
int n;

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)
        cin >> a[i];

    LL sum = 0, ret = -1e6;
    for (int i = 1;i <= n;i++)
    {
        sum += a[i];
        ret = max(sum, ret);
        if (sum < 0) sum = 0;
    }
    cout << ret << endl;
    return 0;
}